home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / FROMUTS / UNIXLIB37B / src / c / rand < prev    next >
Text File  |  1991-09-22  |  2KB  |  96 lines

  1. #ifdef __STDC__
  2. static char sccs_id[] = "@(#) rand.c 1.1 "__DATE__" HJR";
  3. #else
  4. static char sccs_id[] = "@(#) rand.c 1.1 26/9/90 HJR";
  5. #endif
  6.  
  7. /* rand.c (c) Copyright 1990 H.Rogers */
  8.  
  9. #include <stdlib.h>
  10.  
  11. static unsigned long __state[32] =
  12.   {
  13.   0x6fdb9cb7, 0x9de8dc3d, 0x093bf9e4, 0x47528c2b, 0xfc263867, 0x53cbf1bf,
  14.   0x13618c92, 0x9e0f31b1, 0xcd651ab0, 0x2b52a7e5, 0x2ccdd9bf, 0x30052e2e,
  15.   0xb278be81, 0xd634a58b, 0x0a33d2c1, 0xfd42f052, 0xcb2f06f8, 0xa57bb730,
  16.   0x4ca963ac, 0x84bf5532, 0xd67ab9e6, 0x6e2d017b, 0x1e17cd99, 0x5891173a,
  17.   0x39384a29, 0xe0a0282e, 0x2e5512fc, 0x3093f269, 0x3a6983e6, 0x6b9fdaf3,
  18.   0x38b6bbd1, 0xb5e23046
  19.   };
  20. static int __st1 = 0,__st2 = 3;
  21.  
  22. #ifdef __STDC__
  23. void srand(register long seed)
  24. #else
  25. void srand(seed)
  26. register long seed;
  27. #endif
  28. {
  29. register int i;
  30.  
  31. for (i = 0; i < 32; i++)
  32.   seed = __state[i] = (seed * 1103515245 + 12345);
  33. __st1 = 0; __st2 = 3;
  34. for (i = 0; i < ((lrand() ^ seed) & 255); i++);
  35. for (i = 0; i < ((lrand() ^ seed) & 255); i++) lrand();
  36. }
  37.  
  38. #ifdef __STDC__
  39. long lrand(void)
  40. #else
  41. long lrand()
  42. #endif
  43. {
  44. register long i,j;
  45. register int k,l;
  46.  
  47. i = *((long *)(__state + (k = __st1)));
  48. j = *((long *)(__state + (l = __st2)));
  49. if (i < 0 && j < 0) i = -i; __state[l] = (i += j);
  50. __st1 = (k + 1) & 31; __st2 = (l + 1) & 31;
  51. return((i>>1) & RAND_MAX);
  52. }
  53. #ifdef __STDC__
  54. int (rand)(void)
  55. #else
  56. int (rand)()
  57. #endif
  58. {
  59. return(rand());
  60. }
  61.  
  62. #ifdef __STDC__
  63. void (srand48)(register long seed)
  64. #else
  65. void (srand48)(seed)
  66. register long seed;
  67. #endif
  68. {
  69. srand48(seed);
  70. }
  71. #ifdef __STDC__
  72. long (lrand48)(void)
  73. #else
  74. long (lrand48)()
  75. #endif
  76. {
  77. return(lrand48());
  78. }
  79. #ifdef __STDC__
  80. void (srandom)(register long seed)
  81. #else
  82. void (srandom)(seed)
  83. register long seed;
  84. #endif
  85. {
  86. srandom(seed);
  87. }
  88. #ifdef __STDC__
  89. long (random)(void)
  90. #else
  91. long (random)()
  92. #endif
  93. {
  94. return(random());
  95. }
  96.